import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/Contact/AddContact.dart';
import 'package:flutter_app/chat/choose_chat.dart';

class Contact extends StatefulWidget {
  ContactWidget createState() => new ContactWidget();
}

class ContactWidget extends State<Contact> with SingleTickerProviderStateMixin {
  TabController _tabController;

  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: 2);
  }

  Widget build(BuildContext context) {
    return new Scaffold(
      body: Column(
        children: <Widget>[
          TabBar(
            indicatorSize: TabBarIndicatorSize.label,
            indicatorColor: Colors.blueAccent[700],
            unselectedLabelColor: Colors.blueAccent[200],
            labelColor: Colors.blueAccent[700],
            controller: _tabController,
            tabs: <Widget>[
              new Tab(
                text: '好友',
              ),
              new Tab(
                text: '群聊',
              )
            ],
          ),
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: <Widget>[
                ListView.builder(
                    itemCount: 5,
                    itemBuilder: (BuildContext context, int position) {
                      return ListTile(
                        title: Text('好友$position'),
                        leading: Icon(Icons.person_outline),
                        onTap: (){
                          ChooseChat.startChat(context, '好友$position', false);
                        },
                      );
                    }),
                ListView.builder(
                    itemCount: 5,
                    itemBuilder: (BuildContext context, int position) {
                      return ListTile(
                        title: Text('群聊$position'),
                        leading: Icon(Icons.person_outline),
                        onTap: (){
                          ChooseChat.startChat(context, '好友$position', true);
                        },
                      );
                    }),
              ],
            ),
          )
        ],
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
      floatingActionButton: Container(
        padding: EdgeInsets.only(bottom: 12.0),
        child: FloatingActionButton(
          child: Text('添加'),
          onPressed: () {Navigator.push(context,new MaterialPageRoute(builder: (context) => new AddContact()));},
        ),
      ),
    );
  }
}
